package com.whisperly.echotalk.starryb.mutual;

import static com.whisperly.echotalk.starryb.utils.Mutual.checkDomain;

import android.util.Log;
import android.webkit.JavascriptInterface;

public class JsObject {
        private String currentHost;

        @JavascriptInterface
        public String getToken() {
            Log.e("info", "i am in getToken under host:" + currentHost);
            if (checkDomain(currentHost, 1)) //High level of security, trust only chen88.top
            {
                Log.e("info", "allowed to call getToken");
                return "{\"token\":\"1234567890abcdefg\"}";
            } else {
                Log.e("info", "not allowed to load this url");
                return "not allowed to call";
            }

        }

        @JavascriptInterface
        public String getUsername() {
            Log.e("info", "i am in getUsername under host:" + currentHost);
            if (checkDomain(currentHost, 0)) //Low security level, trust chen88.top and chen99.top
            {
                return "{\"userName\":\"root\"}";
            } else
                return "not allowed to call";
        }

        public void setCurrentHost(String currentHost) {
            this.currentHost = currentHost;
        }
    }